package com.elite.controller;

import com.elite.entity.User;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/test")
public class TestController {


	@GetMapping("/hello")
	public String get(Date data) {
		System.out.println("data = " + data);
		return "OK";
	}


	@PostMapping("/hello")
	public String post() {
		return "OK";
	}


	public String test1() {
		return "OK";
	}

	@GetMapping("/date")
	public String testDate(Integer date){
		System.out.println("date = " + date);
		return "OK";
	}

	@GetMapping("/testGetUser")
	public String testGetUser(User user){
		System.out.println("user = " + user);
		return "OK";
	}


	@PostMapping("/testPostUser")
	public User testPostUser(@RequestBody @Validated User user){
		System.out.println("user = " + user);
		return user;
	}


	/**
	 * 测试全局异常处理
	 * @param user
	 * @return
	 */
	@GetMapping("/testException")
	public User testException(@RequestBody User user){
		System.out.println("user = " + user);
		throw new RuntimeException("测试异常");

	}


	/**
	 * 测试 @PathVariable 注解
	 * @param name
	 * @return
	 */
	@GetMapping("/testPathVariable/{name}")
	public User testPathVariable(@PathVariable("name") String name){
		System.out.println("name = " + name);
		return null;
	}
}
